using Model.Core.Entity;
using RobotPratolSolution.ViewModels;
using System.Windows;
using System.Windows.Controls;


namespace RobotPratolSolution.Pages
{
    /// <summary>
    /// SysSetting.xaml 的交互逻辑
    /// </summary>
    public partial class SysSetting : UserControl
{
    private void UpdateData_Click(object sender, RoutedEventArgs e)
    {
        var dialog = new EditRobotDialog();
        
        dialog.DataContext = this.DataContext;
        dialog.Owner = Window.GetWindow(this);
        
        if (dialog.ShowDialog() == true)
        {
            if (DataContext is SysSettingViewModel viewModel && viewModel.SelectedRobot != null)
            {
                viewModel.UpdateRobotConfig(viewModel.SelectedRobot);
            }
        }
    }
    
        SysSettingViewModel sysSettingViewModel { get; set; }
        public SysSetting()
        {
            InitializeComponent();
            sysSettingViewModel = new SysSettingViewModel();
            this.DataContext = sysSettingViewModel;
        }



        private void UseButton_Click(object sender, RoutedEventArgs e)
        {
            var button = sender as Button;
            var dataContext = button?.DataContext as RobotInfo;

            if (dataContext != null && DataContext is SysSettingViewModel viewModel)
            {
                viewModel.UseRobotConfig(dataContext);
            }
        }


        private void UserControl_Loaded(object sender, RoutedEventArgs e)
        {
            sysSettingViewModel.LoadRobotConfig();
        }

        private void AsyncButton_Click(object sender, RoutedEventArgs e)
        {
            //var button = sender as Button;
            //var dataContext = button?.DataContext as RobotInfo;

            //if (dataContext != null && DataContext is SysSettingViewModel viewModel)
            //{
            //    viewModel.SaveRobotConfig(dataContext);
            //}
        }
    }
}
